const Router = require("koa-router");
const multiparty = require("koa2-multiparty");

const {
  avatarHandler,
  pictureHandler,
  pictureResize,
} = require("../middleware/file.middleware");
const { verifyAuth } = require("../middleware/auth.middleware");
const {
  saveAvatarInfo,
  savePictureInfo,
  uploadVideo,
} = require("../controller/file.controller");

const fileRouter = new Router({ prefix: "/upload" });

// 上传头像
fileRouter.post("/avatar", verifyAuth, avatarHandler, saveAvatarInfo);
// 上传图片文件
fileRouter.post(
  "/picture",
  verifyAuth,
  pictureHandler,
  pictureResize,
  savePictureInfo
);
// 上传视频
fileRouter.post("/video", verifyAuth, multiparty(), uploadVideo);

module.exports = fileRouter;
